What is @otplib/preset-default?
@otplib/preset-default is a preset configuration for the otplib (One Time Password Library) that provides default settings for generating and validating one-time passwords (OTPs) using TOTP (Time-based One-Time Password) and HOTP (HMAC-based One-Time Password) algorithms.
What are @otplib/preset-default's main functionalities?
Generate TOTP
This feature allows you to generate a Time-based One-Time Password (TOTP) using a secret key. The generated token is time-sensitive and changes periodically.
const otplib = require('@otplib/preset-default');
const secret = 'KVKFKRCPNZQUYMLXOVYDSQKJKZDTSRLD';
const token = otplib.authenticator.generate(secret);
console.log(token);
Validate TOTP
This feature allows you to validate a given TOTP against a secret key. It returns a boolean indicating whether the token is valid.
const otplib = require('@otplib/preset-default');
const secret = 'KVKFKRCPNZQUYMLXOVYDSQKJKZDTSRLD';
const token = '123456';
const isValid = otplib.authenticator.check(token, secret);
console.log(isValid);
Generate HOTP
This feature allows you to generate an HMAC-based One-Time Password (HOTP) using a secret key and a counter. The generated token is counter-based and changes with each increment of the counter.
const otplib = require('@otplib/preset-default');
const secret = 'KVKFKRCPNZQUYMLXOVYDSQKJKZDTSRLD';
const counter = 1;
const token = otplib.hotp.generate(secret, counter);
console.log(token);
Validate HOTP
This feature allows you to validate a given HOTP against a secret key and a counter. It returns a boolean indicating whether the token is valid.
const otplib = require('@otplib/preset-default');
const secret = 'KVKFKRCPNZQUYMLXOVYDSQKJKZDTSRLD';
const token = '123456';
const counter = 1;
const isValid = otplib.hotp.check(token, secret, counter);
console.log(isValid);
Other packages similar to @otplib/preset-default
speakeasy
Speakeasy is a library for generating and verifying one-time passwords (OTPs) using TOTP and HOTP algorithms. It provides similar functionalities to @otplib/preset-default but with a different API and additional features like QR code generation.
notp
notp is a library for generating and verifying TOTP and HOTP tokens. It offers a simpler API compared to @otplib/preset-default and is suitable for basic OTP functionalities.
otpauth
otpauth is a library for generating and validating OTPs using TOTP and HOTP algorithms. It provides a more flexible and customizable API compared to @otplib/preset-default, allowing for more advanced use cases.
@otplib/preset-default
otplib node bundle with pre-configured plugins to get started quickly.
See our project readme for more information
or visit the demo website.
Install
npm install --save @otplib/preset-default
License
@otplib/preset-default
is MIT licensed